package com.qyzmt.controller;

import com.qyzmt.pojo.Result;
import com.qyzmt.pojo.Volunteer;
import com.qyzmt.service.VolunteerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/api")
@RestController
public class VolunteerController {

    @Autowired
    private VolunteerService volunteerService;

   // 列出全部志愿者
    @GetMapping("/volunteers")
    public Result list(){
        log.info("自定义日志：Request All Volunteers SQL.");
        List<Volunteer> volunteerList = volunteerService.list();
        return Result.success(volunteerList);
    }

    // 新增志愿者
    @PostMapping("/volunteers")
    public Result add(@RequestBody Volunteer volunteer){
        log.info("用户新增志愿者:{}",volunteer);
        volunteerService.add(volunteer);
        return Result.success();


    }

}
